import request from "../utils/request.js";

export const getCarousel = () => {
  return request({
    method: "get",
    url: "/carousel",
  });
};

export const getGoodsImg = () => {
  return request({
    method: "get",
    url: "/ProductPicture",
  });
};

export const getGoodsData = () => {
  return request({
    method: "get",
    url: "/Product",
  });
};

export const getShoppingCart = () => {
  return request({
    method: "get",
    url: "/ShoppingCart",
  });
};

export const postShoppingCart = (obj) => {
  return request({
    method: "post",
    url: "/ShoppingCart",
    data: obj,
  });
};

export const patchShoppingCart = ({ id, count }) => {
  return request({
    method: "patch",
    url: "/ShoppingCart/" + id,
    data: {
      count,
    },
  });
};

export const getProduct = () => {
  return request({
    method: "get",
    url: "/Product",
  });
};
export const getPagegetProduct = ({ page, limit }) => {
  return request({
    method: "get",
    url: `/Product?_page=${page}&_limit=${limit}`,
  });
};
export const getCategory = () => {
  return request({
    method: "get",
    url: "/category",
  });
};
export const getUser = () => {
  return request({
    method: "get",
    url: "/users",
  });
};

export const postUser = ({ id, name, pass }) => {
  return request({
    method: "post",
    url: "/users",
  });
};

export const getShoppingCarts = (id) => {
  return request({
    method: "get",
    url: `/ShoppingCart?user_id=${id}`,
  });
};

export const deleteShoppingCart = (id) => {
  return request({
    method: "delete",
    url: "/ShoppingCart/" + id,
  });
};

export const getSearch = (keyword) => {
  return request({
    method: "get",
    url: `/Product?q=${keyword}`,
  });
};
